<?php
class Advertising extends MY_Controller{
	function get_ad_list() {
		$post_data = $this->user_post_data;
		if(empty($post_data['ad_position_sign'])) {
			$result_data = array('code' => 0, 'msg' => "缺少数据");
		}else {
			$ad_list = array();
			$this->load->model("Advertisings");
			$ad_list = $this->Advertisings->get_ad_list($post_data['ad_position_sign']);
			foreach ($ad_list as $k => $v) {
				if($v['ad_type'] == 2){
					$info = get_field_by_where("user", "head_img_url", "id='{$v['top_id']}'");
					if($v['ad_image_url'] == '' && $info['image'] != ''){
						$ad_list[$k]['ad_image_url'] = $info['head_img_url'];
					}
				}elseif($v['ad_type'] == 3){
					$info = get_field_by_where("task_types", "*", "id='{$v['top_id']}'");
					$ad_list[$k]['info'] = json_encode($info);
					if($v['ad_image_url'] == '' && $info['image'] != ''){
						$ad_list[$k]['ad_image_url'] = $info['image'];
					}
				}elseif ($v['ad_type'] == 4) {
					$info = get_field_by_where("articles", "img", "id='{$v['top_id']}'");
					if($v['ad_image_url'] == '' && $info['image'] != ''){
						$ad_list[$k]['ad_image_url'] = $info['img'];
					}
				}elseif ($v['ad_type'] == 5) {
					$info = get_field_by_where("books", "image", "id='{$v['top_id']}'");
					if($v['ad_image_url'] == '' && $info['image'] != ''){
						$ad_list[$k]['ad_image_url'] = $info['image'];
					}
				}elseif ($v['ad_type'] == 6) {
					$info = get_field_by_where("gifts", "image", "id='{$v['top_id']}'");
					if($v['ad_image_url'] == '' && $info['image'] != ''){
						$ad_list[$k]['ad_image_url'] = $info['image'];
					}
				}
			}
			$result_data['code'] = 1;
			$result_data['data'] = $ad_list;
		}
		echo json_encode($result_data);
	}
}